<?php


/**
 * Every informations available about a kit
 */
class KitBean extends DataBean {

    function KitBean($id) {
        $this->id=$id;
        // loading kit cfg
        $cfg=Webappkit::getCfgFromId($id); // print_r($cfg);
        $this->desc=$cfg['kit']['desc'];
        $this->link=$cfg['kit']['link'];
        $this->version=$cfg['kit']['version'];
        $this->phpversion=$cfg['kit']['phpversion'];
        $this->dependencies=$cfg['load_kits'];
        // listing subkits
        $subkits=Webappkit::listKits(Webappkit::getPathFromId($id));
        foreach ($subkits as $subkit) {
            $subid=$id.'.'.$subkit; // echo "<p>$subid</p>";
            $this->subkits[$subkit]=new KitBean($subid);
        }
        // has tests ?
        $this->has_tests=isset($cfg['tools']['tests']);
        // diagnostics
        // trying to load kit
        // Webappkit::getkit($id);
    }

    var $id;

    var $kit;
    function _kit_get() {
        if ($this->kit)
            return $this->kit;
        $this->kit=Webappkit::getKit($this->id);
        return $this->kit;
    }

    var $desc;

    var $link;

    var $version;

    var $phpversion;

    /**
     * @var array id => KitBean
     */
    var $subkits=array();

    var $has_tests=false;

    var $tests_report;
    function _tests_report_get() {
        if (!isset($this->tests_report)) {
            $kit=$this->get('kit');
            if ($kit->tests)
                $this->tests_report=$kit->tests->run();
        }
        // print_r($this->tests_report);
        return $this->tests_report;
    }

    var $error;
}
